<!--
    详情单个item
-->
<template>
    <div class="detail-item" :style="{ width: (100 / _column) + '%' }">
        <span class="detail-label" :style="{ width: _labelWith }">
            <slot name="label">{{ label }}：</slot>
        </span>
        <!-- 单张图片  -->
        <div class="img-single" v-if="detailType === 'image'">
            <a-image class="img-item" :src="imgUrl" />
        </div>
        <!-- 多张图片 -->
        <div class="img-list" v-else-if="detailType === 'imageList'">
            <a-image-preview-group>
                <a-image
                    v-for="(item, index) in imgUrlList"
                    class="img-list-item"
                    :key="index"
                    :src="item"
                />
            </a-image-preview-group>
        </div>
        <span v-else class="detail-content">
            <slot name="text">{{ text }}</slot>
        </span>
    </div>
</template>

<script lang="ts" setup>
import { inject } from 'vue'
import type { detailType } from './type'
interface detailItemType {
    label?: string,
    text?: string,
    labelWidth?: string,
    span?: number,
    imgUrl?: string,
    imgUrlList?: string[],
    detailType: detailType,
    labelStyle?: Partial<CSSStyleDeclaration>
}
const props = withDefaults(defineProps<detailItemType>(), {
    detailType: 'text'
})
const labelWidth: string | undefined = inject('labelWidth')
const labelStyle: Partial<CSSStyleDeclaration> | null | undefined = inject('labelStyle')
const column: number = inject('column') as number
let _labelWith = props.labelWidth ? props.labelWidth : labelWidth
// let _labelStyle = props.labelStyle ? props.labelStyle : labelStyle
let _column = props.span ? (24 / props.span) : column
</script>

<style lang="less" scoped>
.detail-item {
    width: 50%;
    display: inline-flex;
    line-height: 20px;
    padding: 0 20px;
    margin-bottom: 20px;
    font-size: 15px;

    .detail-label {
        width: 90px;
        height: 40px;
        display: flex;
        align-items: flex-start;
        justify-content: flex-start;
        text-align: left;
        flex-shrink: 0;
        color: #7d7989;
        font-weight: bold;
    }

    .detail-content {
        color: black;
        word-break: break-all;
    }

    .img-single {
        :deep(.ant-image-img) {
            width: 180px !important;
            height: 180px !important;
            border-radius: 4px;
            cursor: pointer;
            object-fit: cover;
        }
    }

    .img-list {
        :deep(.ant-image-img) {
            width: 180px !important;
            height: 180px !important;
            border-radius: 4px;
            cursor: pointer;
            margin-right: 6px;
            margin-bottom: 6px;
            object-fit: cover;
        }
    }
}
</style>
